<?php 
//Security Checking for the user if allowed to login.
session_start();
if(strlen($_SESSION['u_name'])==0)
{
	?>
	<script>
	window.open("admin-login.php","_self");
	</script>
	<?php 
	exit;
}

//#########INCLUDE FILES########
include_once '../conf/db-config.php';
include_once '../conf/error.php';
include_once '../clsFetchData.php';
include_once '../array_to_xml.php';
include_once 'city-name.php';
//##############################

?>
<html>
<style type="text/css">
.body {
	background-color:#a6bf79;
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	margin: 10px 10px 10px 10px;
	padding: 0px;
}
.textLike
{
	color:#000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	padding: 0px;
}
</style>
<title>Admin -HomePage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="../js/jquery-1.4.2.js" type="text/javascript" language="javascript"></script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/menu.css" rel="stylesheet" type="text/css" />
</head>
<body class="body">
<div id="body" style="width:960px;">
<div align="center">
<!-- Admin Home Page Menu Bar -->

<ul id="list-nav">
<li><a href="admin-homepage.php">Home</a></li>
<li><a href="admin-homepage.php">All Listings</a></li>
<!--<li><a href="approved-listing.php">Approved Listing</a></li>-->
<li><a href="unapproved-listing.php">Deactivated Listing</a></li>
<li><a href="new-listing.php">New Lists</a></li>
<li><a href="admin-themelist.php">Theme List</a></li>
<li><a href="secure.php?logout=yes">Log Out</a></li>
</ul>


<!-- Menu Bar Ends -->
</div>
<br />
</head>
<body class="body">
<div style="width:960px;">

<table width="75%" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="20px" align="right" style="padding-right: 0px;">
<a href="changepassword.php">Change Password</a>
</td>
</tr>
<tr>
<td>
	<style media="all" type="text/css">@import "../css/menu.css";</style>
	
</td>
</tr>

<?php 

$arrCityNames = array();
$objFetchData = new clsFetchData();
$arrCityNames = $objFetchData->fetchAllCity();

if(isset($_REQUEST['uid']))
{
	$action = "edit";
}
if($action=="edit")
{
	$editedId = $_REQUEST['uid'];
	
	$sql = "SELECT user_name,password,user_email FROM tbl_users WHERE id=$editedId";
	$run = mysql_query($sql);
	while ($data = mysql_fetch_array($run))
	{
		$user_name = $data['user_name'];
		$password = $data['password'];
		$userEmail = $data['user_email'];
	}
	$sql2 = "SELECT city FROM tbl_user_city WHERE user_id=$editedId";
	$run2 = mysql_query($sql2);
	$count=0;
	while ($data2 = mysql_fetch_array($run2))
	{
		$arrCity[$count] = $data2['city'];
		$count++;
	}
}

?>
<tr>
<td>

</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>

<?php 

if($_REQUEST['error']=="duplicateuser")
{
	?>
	<tr>
		<td style="color: red;">You can not create duplicate user.</td>
	</tr>
	
	<?php 
}

?>


<tr>
<td width="500">
<form id="frmAddUser" name="frmAddUser" method="post" action="save-user-city.php">
<fieldset>
<legend>Create User and Assign To City</legend>
<table cellpadding='0' cellspacing='0' border="0" align="center" style="padding:10px 0 0 10px;">
	<tr>
		<td>
		Username: 
		</td>
		<td>
		&nbsp;
		</td>
		<td>
		<input type='text' value="<?php echo $user_name; ?>" name='txtusername' id='txtusername' size="40" />
		</td>
	</tr>
	<tr>
		<td colspan='3'>&nbsp;
		</td>
	</tr>
	<tr>
		<td>
		User Temporary Password:
		</td>
		<td>
		&nbsp;
		</td>
		<td>
		<input type="password" value="<?php echo $password; ?>" name='txtTempPass' id='txtTempPass' size="40" />
		</td>
	</tr>
	<tr>
		<td colspan='3'>&nbsp;
		</td>
	</tr>
	<tr>
		<td>
		User Email Id:
		</td>
		<td>
		&nbsp;
		</td>
		<td>
		<input type='text' value="<?php echo $userEmail; ?>" name='txtEmailId' id='txtEmailId' size="40" />
		</td>
	</tr>
	<tr>
		<td colspan='3'>&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			Choose City:
		</td>
		<td colspan='2'>
		<?php 
		//print_r($arrCity);
		?>
		<!-- MULTIPLE SELECT BOX -->
		<select id="selectCityName" name="selectCityName[]" multiple="multiple" style="width: 270px;">
		<?php 
		
		foreach($arrCityNames as $vals)
		{
			if(in_array($vals,$arrCity))
			{
				$selected="selected='selected'";
			}
			else
			{
				$selected="";
			}
			?>
			<option <?php echo $selected; ?> value="<?php echo $vals; ?>"><?php echo ucfirst($vals); ?></option>
			<?php 
			
		}
		?>
		</select>
		
		<!-- MULTIPLE SELECT BOX ENDS -->
		</td>
	</tr>
	<tr>
		<td colspan='3'>&nbsp;
		</td>
	</tr>
	<tr>
		<td colspan="3" align="center">
			<?php if($action!="edit") { ?>
			<input type="submit" id="btnAssignUser" name="btnAssignUser" value="Add & Assign User >>" class="normalBtn" />
			<?php } else { ?>
			<input type="submit" id="btnAssignUser" name="btnAssignUser" value="Update User Data >>" class="normalBtn"  />
			<input type="hidden" id="hdnUpdate" name="hdnUpdate" value="update" />
			<input type="hidden" id="hdnUserId" name="hdnUserId" value="<?php echo $editedId; ?>" />
			<?php } ?>
		</td>
	</tr>
	</table>
	</fieldset>
	</form>
</td>
</tr>
</table>
</div>
</body>
</html>